from django.contrib import admin

# Register your models here.
from booktest.models import BookInfo, HeroInfo


class HeroInfoStackInline(admin.TabularInline):
    """关联展示数据"""
    model = HeroInfo  # 关联查询那个模型的数据
    extra = 1  # 额外的编辑页面


# @admin.register(BookInfo)
class BookInfoAdmin(admin.ModelAdmin):
    # list_per_page = 2
    actions_on_bottom = True  # 底部操作选项框

    list_display = ['id', 'btitle', 'bread', 'pub_date', 'bcomment']

    # fields = ['btitle', 'bpub_date']  # 编辑界面可以修改字段

    fieldsets = (
        ('基本', {'fields': ['btitle', 'bpub_date', 'image']}),
        ('高级', {
            'fields': ['bread', 'bcomment'],
            'classes': ('collapse',)  # 是否折叠显示
        })
    )

    inlines = [HeroInfoStackInline]



@admin.register(HeroInfo)
class HeroInfoAdmin(admin.ModelAdmin):
    list_display = ['id', 'hname', 'hbook', 'hcomment', 'read']

    list_filter = ['hbook', 'hgender']  # 列表界面右边显示的过滤器
    search_fields = ['hname']  # 搜索框


admin.site.register(BookInfo, BookInfoAdmin)
# admin.site.register(HeroInfo)

admin.site.site_header = '传智书城'
admin.site.site_title = '传智书城MIS'
admin.site.index_title = '欢迎使用传智书城MIS'


